﻿using System;
using System.Collections.Generic;
using FBEntities.FBConnections;
using Newtonsoft.Json.Linq;
using XDAFacebook;
using XFControls.Utils;

namespace FBEntities.FBObjects
{
    public class FBComments : IFBObject
    {
        public int count;
        public List<FBComment> data;
        public FBPaging paging;

        public FBComments()
        {
            data = new List<FBComment>();
        }

        #region IFBObject Members

        public void Parse(JObject text)
        {
            FBParseUtilities.Parse(text, this);
        }

        #endregion
    }

    public class FBComment : IFBObject
    {
        public DateTime created_time;
        public FBFrom from;
        public string id;
        public string message;
        public int likes;

        #region IFBObject Members

        public void Parse(JObject text)
        {
            FBParseUtilities.Parse(text, this);
        }

        #endregion

        public void Parse()
        {
            if (string.IsNullOrEmpty(id))
                return;

            string url = "https://graph." + Settings.Domain + ".com/" + id + "?" + FBParseUtilities.authKey;
            var wrapper = new WebDownloaderWrapper(url);
            string json = wrapper.Download();
            JObject o = JObject.Parse(json);
            Parse(o);
        }


        public FBPost ToPost()
        {
            var ret = new FBPost();
            ret.id = id;
            ret.from = from;
            ret.message = message;
            ret.created_time = created_time;
            ret.type = "comment";
            ret.PeopleWhoLiked = new FBLikesConnection {count = likes};

            ret.actions.Add(new FBAction { name = "Like" });
            ret.actions.Add(new FBAction { name = "Comment" });

            return ret;
        }
    }

    public class FBPaging : IFBObject
    {
        public string next;
        public string previous;

        #region IFBObject Members

        public void Parse(JObject text)
        {
            FBParseUtilities.Parse(text, this);
        }

        #endregion
    }

    public class FBStatus : IFBObject
    {
        public FBFrom from;
        public string id;
        public string message;
        public DateTime updated_time;

        #region IFBObject Members

        public void Parse(JObject text)
        {
            FBParseUtilities.Parse(text, this);
        }

        #endregion
    }
}